﻿using DDD.Domain;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoodsModule.Domain.GoodsAggregate
{
    public record GoodsImageId(long Id);// : IKey;
    [Comment("商品相册")]
    [Table("WbGoodsImage")]
    public class GoodsImage : Entity<long>
    {
        #region 字段
        /// <summary>
        /// 排序
        /// </summary>
        [Comment("排序")]
        [Required]
        public uint Sort { get; private set; } = 1000;

        /// <summary>
        /// 文件名
        /// </summary>
        [Comment("文件名")]
        [Required]
        [StringLength(100)]
        [MaxLength(100)]
        public string Name { get; private set; } = string.Empty;

        /// <summary>
        /// 文件路径
        /// </summary>
        [Comment("文件路径")]
        [Required]
        [StringLength(100)]
        [MaxLength(100)]
        public string Path { get; private set; } = string.Empty;

        /// <summary>
        /// 扩展名
        /// </summary>
        [Comment("扩展名")]
        [Required]
        [StringLength(10)]
        [MaxLength(10)]
        public string Ext { get; private set; } = string.Empty;

        /// <summary>
        /// 文件大小
        /// </summary>
        [Comment("文件大小")]
        [Required]
        [Range(0, uint.MaxValue)]
        public uint Size { get; private set; }

        /// <summary>
        /// 标题
        /// </summary>
        [Comment("标题")]
        [Required]
        [StringLength(100)]
        [MaxLength(100)]
        public string Title { get; private set; } = string.Empty;

        /// <summary>
        /// 标签
        /// </summary>
        [Comment("标签")]
        [Required]
        [StringLength(1000)]
        [MaxLength(1000)]
        public string Tags { get; private set; } = ",";
        #endregion

        private GoodsImage() { }

        public GoodsImage(string title, string name, string path, string ext, uint size, uint sort = 1000, string tags = ",")
        {
            Sort = sort;
            Name = name ?? throw new ArgumentNullException(nameof(name));
            Path = path ?? throw new ArgumentNullException(nameof(path));
            Ext = ext ?? throw new ArgumentNullException(nameof(ext));
            Size = size;
            Title = title ?? throw new ArgumentNullException(nameof(title));
            Tags = tags ?? throw new ArgumentNullException(nameof(tags));
        }

    }
}
